/*
 * Group:PrePool K9-357 
 * 8/2010
 */
package blo;

import java.util.ArrayList;
import java.util.List;

import org.apache.log4j.Logger;

import util.Constants;
import dao.LanguagesDAO;
import dto.LanguageDTO;

/**
 *
 */

public class LanguagesBLO {
	public static Logger LOG = Logger.getLogger("blo.LanguagesBLO");
	private LanguagesDAO langDAO = new LanguagesDAO();

	/**
	 * @param name
	 *            name of language
	 * @return true if successful,false if fail
	 */
	public boolean addLanguage(String name) {
		return langDAO.addLanguage(name);
	}

	/**
	 * @param name
	 *            name of language
	 * @return true if successful,false if fail
	 */
	public boolean removeLanguage(String name) {
		return langDAO.removeLanguage(name);
	}

	/**
	 * @param langId
	 *            id of language
	 * @return true if successful,false if fail
	 */
	public boolean removeLanguage(int langId) {
		return langDAO.removeLanguage(langId);
	}

	/**
	 * @param fromLangId
	 *            ID of language
	 * @return HTML option section code for this language
	 */
	public String getListHTML(int fromLangId) {
		if (fromLangId < 0)
			return getListHTML();
		else {
			List<LanguageDTO> listLanguage = new ArrayList<LanguageDTO>();
			String list = Constants.BLANK_STRING;
			listLanguage = langDAO.getAvailableLanguage(fromLangId);
			
			for (int i = 0; i < listLanguage.size(); ++i) {
				list += "<option value=" + listLanguage.get(i).getId() + ">"
						+ listLanguage.get(i).getName() + "</option>";
			}
			return list;
		}
	}

	/**
	 * @return
	 */
	public String getListHTML() {
		List<LanguageDTO> listLanguage = new ArrayList<LanguageDTO>();
		String list = Constants.BLANK_STRING;
		listLanguage = langDAO.getLangList();
		
		for (int i = 0; i < listLanguage.size(); ++i) {
			list += "<option value=" + listLanguage.get(i).getId() + ">"
					+ listLanguage.get(i).getName() + "</option>";
		}
		return list;
	}

}
